package com.zxc.shop.user.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxc.shop.common.utils.PageUtils;
import com.zxc.shop.common.utils.Query;
import com.zxc.shop.user.dao.UserDao;
import com.zxc.shop.user.entity.UserEntity;
import com.zxc.shop.user.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        // 1.创建分页对象
        IPage<UserEntity> page1 = new Query<UserEntity>().getPage(params);

        // 2.创建查询对象
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        Object username = params.get("username");
        if (username != null && !StringUtils.isEmpty(username.toString())) {
            queryWrapper.like("username", username);
        }

        // 3.组合条件查询
        IPage<UserEntity> page = this.page(page1, queryWrapper);

        return new PageUtils(page);
    }

}